package com.boarsoft.flow.demo.make;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.boarsoft.flow.core.bean.JoinHandler;

public class MakeMoneyJoinHandlerImpl implements JoinHandler {
	private static final Logger log = LoggerFactory.getLogger(MakeMoneyJoinHandlerImpl.class);

	@SuppressWarnings("unchecked")
	@Override
	public Object join(Object flowData, Map<String, Object> resultMap) {
		Map<String, Object> pm = (Map<String, Object>) flowData;
		String userId = (String) pm.get("userId");
		Long total = (Long) pm.get("money");
		if (total == null) {
			total = 0L;
		}
		for (String k : resultMap.keySet()) {
			Long v = (Long) resultMap.get(k);
			total += v;
		}
		pm.put("money", total);
		log.info("User {} make total {}", userId, total);
		return pm;
	}
}
